//
//  RootViewController.m
//  DongChiDaChiProject1
//
//  Created by lanou3g on 15/10/27.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "RootViewController.h"
#import "MainViewController.h"
#import "MineViewController.h"
#import "EightViewController.h"
#import "MapViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置 Tabbar 的背景颜色
    UIView *tabBarView = [[UIView alloc] initWithFrame:self.tabBar.bounds];
    tabBarView.backgroundColor = [UIColor colorWithHue:0.1 saturation:0.3 brightness:1 alpha:1];
    [self.tabBar insertSubview:tabBarView atIndex:1];
    self.tabBar.opaque = YES;
    // Do any additional setup after loading the view.
    // 添加VC
    [self addVC];
    
}


- (void)addVC
{
    // 添加视图控制器
    [self addViewControllerClass:[MainViewController class] title:@"菜谱" image:@"caipu3.png"];
    [self addViewControllerClass:[EightViewController class] title:@"食客说" image:@"shikeshuo3.png"];
    [self addViewControllerClass:[MapViewController class] title:@"推荐" image:@"tuijian4.png"];
    [self addViewControllerClass:[MineViewController class] title:@"我的" image:@"wode3.png"];
    
    
}


// 封装一个方法来添加UIViewController
- (void)addViewControllerClass:(Class)class title:(NSString *)title image:(NSString *)imageName
{
    UIViewController *tempVC = [[class alloc] init];
    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:tempVC];
    naVC.tabBarItem.title = title;
    
    naVC.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //naVC.tabBarItem.image = [UIImage imageNamed:imageName];
    
    [self addChildViewController:naVC];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)shouldAutorotate   // 是否允许旋转
{
        return NO;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

{

    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
